package com.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PmboxFilter implements Filter {
    private static Logger log = LoggerFactory.getLogger(PmboxFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        String path = ((HttpServletRequest) request).getContextPath();
        request.setAttribute("path", path);
        HttpServletRequest req = (HttpServletRequest) request;
        String request_url = req.getRequestURL().toString();
        String queryString = req.getQueryString();
        String url = StringUtils.isEmpty(queryString) ? request_url : request_url.concat("?").concat(queryString);
        request.setAttribute("request_url", url);
        log.info("===========================微信分享加签url:" + url);

        chain.doFilter(request, response);
    }

    @Override
    public void destroy() {

    }

}
